package com.cuhk.gulimall.search.web;

import com.cuhk.gulimall.search.service.MallSearchService;
import com.cuhk.gulimall.search.vo.SearchParam;
import com.cuhk.gulimall.search.vo.SearchResult;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
public class ListController {

    @Autowired
    private MallSearchService mallSearchService;

    @GetMapping(value="/list.html")
    public String listPage(Model model, SearchParam searchParam, HttpServletRequest request) {
        //String queryString = request.getQueryString();
        //searchParam.set_queryString(queryString);
        System.out.println("请求URL" + request.getRequestURL().toString());
        SearchResult searchResult = mallSearchService.search(searchParam, request.getQueryString());
        model.addAttribute("searchResult", searchResult);
        // modelAndView.setViewName("list");
        return "list";
    }

    /*
    @GetMapping({"/", "/list.html"})
    @ResponseBody
    public SearchResult listPage(ModelAndView modelAndView, SearchParam searchParam) {
        SearchResult searchResult = mallSearchService.search(searchParam);
        modelAndView.addObject("searchResult", searchResult);
        modelAndView.setViewName("list");
        return searchResult;
    }

     */
}
